package com.muqi.app.user.widget;


import com.muqi.app.qlearn.student.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

public class TwoItemsWindow extends PopupWindow implements OnClickListener {
	private View conentView;
	private PopWindowListener naviListener;
	
	@SuppressLint("InflateParams") @SuppressWarnings("deprecation")
	public TwoItemsWindow(final Activity context,String item1,String item2, PopWindowListener naviListener) {
		this.naviListener = naviListener;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_dialog_two_items, null);
		//int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w/3);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		TextView txName1 = (TextView) conentView.findViewById(R.id.itemName1);
		txName1.setText(item1);
		TextView txName2 = (TextView) conentView.findViewById(R.id.itemName2);
		txName2.setText(item2);
		LinearLayout onItem1 = (LinearLayout) conentView.findViewById(R.id.pop_select_item1);
		LinearLayout onItem2 = (LinearLayout) conentView.findViewById(R.id.pop_select_item2);
		onItem1.setOnClickListener(this);
		onItem2.setOnClickListener(this);
	}

	/**   
	 * showPopupWidow
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			this.showAsDropDown(parent, 0 , 5);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.pop_select_item1:
			naviListener.onItemsClik(1);
			break;
		case R.id.pop_select_item2:
			naviListener.onItemsClik(2);
			break;
		default:
			break;
		}
		this.dismiss();
	}
	
	public interface PopWindowListener{
		public void onItemsClik(int position);
	}
}
